﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
using DotNetSkin;
using System.Windows.Forms;

namespace CarInfor.DAL
{
    public static class MyGlobal
    {
        public static UserInfor curUser = null;
        public static SkinUI shinUI1 = null;
        private static readonly XmlDocument xmlDoc = null;

        static MyGlobal()
        {
            string filename = System.Windows.Forms.Application.StartupPath + "\\Config.xml";
            xmlDoc = new XmlDocument();
            xmlDoc.Load(filename);
        }

        /// <summary>
        /// 短信猫安装路径
        /// </summary>
        public static string SmsPath
        {
            get
            {
                XmlNode node = xmlDoc.SelectSingleNode("Setting/MsgPath");
                if (node != null)
                {
                    return node.InnerText;
                }
                return string.Empty;
            }
        }

        /// <summary>
        /// 列表分页大小
        /// </summary>
        public static int PageSize
        {
            get
            {
                XmlNode node = xmlDoc.SelectSingleNode("Setting/PageSize");
                if (node != null)
                {
                    return int.Parse(node.InnerText);
                }
                return 20;
            }
        }

        /// <summary>
        /// 皮肤文件名称
        /// </summary>
        public static string ShinkFile
        {
            get
            {
                XmlNode node = xmlDoc.SelectSingleNode("Setting/SkinFile");
                if (node != null)
                {
                    return node.InnerText;
                }
                return string.Empty;
            }
        }

        /// <summary>
        /// 获取皮肤文件
        /// </summary>
        /// <returns></returns>
        public static Dictionary<string, string> GetSkinFiles()
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            DirectoryInfo dir = new DirectoryInfo(System.Windows.Forms.Application.StartupPath + "\\Skins");
            FileInfo[] fileList = dir.GetFiles();
            if (fileList != null && fileList.Count() > 0)
            {
                foreach (FileInfo file in fileList)
                {
                    dic.Add(file.Name, file.Name.Substring(0, file.Name.LastIndexOf(".")));
                }
            }
            return dic;
        }
    }
}
